package com.lzb.yabbs.util;

import java.util.Date;

/**
 * Created by liuzaibing on 2015/9/7.
 */
public class TimeManager {

    /**
     * 得到距离现在的时间
     * @param fromTime  之前的某个时间
     * @return
     */
    public static String getTimeToNow(Date fromTime){
        Date nowTime=new Date(System.currentTimeMillis());

        System.out.println("from year month day hour min second:"+fromTime.getYear()+" "+fromTime.getMonth()+" "+fromTime.getDate()+" "+fromTime.getHours()+" "+fromTime.getMinutes()+" "+fromTime.getSeconds());
        System.out.println("now year month day hour min second:"+nowTime.getYear()+" "+nowTime.getMonth()+" "+nowTime.getDate()+" "+nowTime.getHours()+" "+nowTime.getMinutes()+" "+nowTime.getSeconds());
        if(fromTime.getYear()!=nowTime.getYear()){
            return nowTime.getYear()-fromTime.getYear()+"年前";

        }else if(fromTime.getMonth()!=nowTime.getMonth()){
            return nowTime.getMonth()-fromTime.getMonth()+"月前";

        }else if(fromTime.getDate()!=nowTime.getDate()){
            return nowTime.getDate()-fromTime.getDate()+"天前";

        }else if(fromTime.getHours()!=nowTime.getHours()){
            return nowTime.getHours()-fromTime.getHours()+"小时前";

        }else if(fromTime.getMinutes()!=nowTime.getMinutes()){
            return nowTime.getMinutes()-fromTime.getMinutes()+"分钟前";

        }else if(fromTime.getSeconds()!=nowTime.getSeconds()){
            return nowTime.getSeconds()-fromTime.getSeconds()+"秒前";
        }
        return null;
    }
}
